<script>

/**
 * Orders Component
 */
export default {
  data() {
    return {
      ordersData: [
        {
          name: "总理-出访",
          flowId: "b45fb98d2a564c23ba623a377d5e12e9",
          domainName: "1",
          seedNum: "1",
          type: "资讯",
          collectionNum: "0",
          cron: "0 0 22 * * ?",
          updateTime: "2021-12-02 10:05",
          runningState: "正常",
          seedswitch: false,
        },{
          name: "总理-出席",
          flowId: "b45fb98d2a564c23ba623a377d5e12e9",
          domainName: "1",
          seedNum: "0",
          type: "资讯",
          collectionNum: "0",
          cron: "0 0 22 * * ?",
          updateTime: "2021-12-02 10:05",
          runningState: "正常",
          seedswitch: false,
        },{
          name: "韩正副总理",
          flowId: "b45fb98d2a564c23ba623a377d5e12e9",
          domainName: "1",
          seedNum: "0",
          type: "资讯",
          collectionNum: "0",
          cron: "0 0 22 * * ?",
          updateTime: "2021-12-02 10:05",
          runningState: "正常",
          seedswitch: false,
        },{
          name: "新闻-要闻",
          flowId: "b45fb98d2a564c23ba623a377d5e12e9",
          domainName: "1",
          seedNum: "0",
          type: "资讯",
          collectionNum: "0",
          cron: "0 0 22 * * ?",
          updateTime: "2021-12-02 10:05",
          runningState: "正常",
          seedswitch: false,
        },{
          name: "总理-最新",
          flowId: "b45fb98d2a564c23ba623a377d5e12e9",
          domainName: "1",
          seedNum: "0",
          type: "资讯",
          collectionNum: "0",
          cron: "0 0 22 * * ?",
          updateTime: "2021-12-02 10:05",
          runningState: "正常",
          seedswitch: false,
        },{
          name: "总理-会议",
          flowId: "b45fb98d2a564c23ba623a377d5e12e9",
          domainName: "1",
          seedNum: "0",
          type: "资讯",
          collectionNum: "0",
          cron: "0 0 22 * * ?",
          updateTime: "2021-12-02 10:05",
          runningState: "正常",
          seedswitch: false,
        }
      ],
      totalRows: 100,
      currentPage: 1,
      perPage: 10,
      fields: [
        { key: "name", label: "种子名称" },
        { key: "domainName", label: "优先级" },
        { key: "type", label: "采集类型" },
        { key: "seedNum", label: "今日采集量" },
        { key: "collectionNum", label: "总计采集量" },
        { key: "cron", label: "定时规则" },
        { key: "updateTime", label: "最后运行时间" },
        { key: "runningState", label: "运行状态" },
        { key: "seedswitch", label: "种子开关" },
        { key: "viewState", label: "查看状态" },
        { key: "configure", label: "抓取配置" }
      ],
      sourceinp: '',
      submitted: false,
      checked: false,
    };
  },
  watch: {
    "currentPage": {
      handler(){
        console.log("触发更新");
      }
    }
  },
  methods: {
    /**
     * Search the table data with search input
     */
    onFiltered(filteredItems) {
      // Trigger pagination to update the number of buttons/pages due to filtering
      this.totalRows = filteredItems.length;
      this.currentPage = 1;
    },
    // 信源搜索
    sourceSearch(){
      this.submitted = true
    },
    // 种子详情
    seedDetail(row){
      console.log(row);
      this.$router.push('/spider/siteDetail')
    },
    goSpiderDetailPage(flowId){
      let routeUrl = this.$router.resolve({
        path: '/spider_detail/' + flowId
      });
      window.open(routeUrl.href, '_blank');
      // this.$router.push('/spider_detail/' + flowId)
    },
    // 全部启动/关闭
    allswitch(status){
      for (let i = 0; i < this.ordersData.length; i++) {
        this.ordersData[i].seedswitch = status
      }
    },
    changeswitch(row){
      this.ordersData[row.index].seedswitch = row.value
      console.log(this.ordersData);
    },
    journal(item){
      console.log(item);
      this.$router.push("/log")
    },
    datahouse(item){
      console.log(item);
      this.$router.push("/datahouse")
    },
  }
};
</script>

<template>
  <div class="card">
    <div class="form-inline" style="padding: 0 1.25rem;margin-bottom:20px;">
      <div class="search-box" style="width: 100%;">
        <div class="position-relative">
          <input
            type="text"
            class="form-control"
            @keyup.enter="sourceSearch"
            v-model="sourceinp"
            placeholder="请输入信源关键词搜索"
            :class="{ 'is-invalid': submitted && sourceinp=='' }"
          />
          <i class="mdi mdi-magnify search-icon"></i>
        </div>
      </div>
      <div :class="{ 'showerror': submitted && sourceinp=='' }" style="margin-left: 0.5rem !important;" class="invalid-feedback">
        <span>请输入信源关键词搜索</span>
      </div>
      <div class="allNum">
        <div class="searchNum">为您检索到<span>5,000+</span>条信息</div>
        <div>
          <b-dropdown dropup variant="secondary" class="butn">
            <template slot="button-content">
              <i class="ri-add-line align-middle" style="font-size: 1rem;"></i>
              <span style="margin:0 20px 0 6px;">采集管理</span>
              <i class="mdi mdi-chevron-up"></i>
            </template>
            <b-dropdown-item-button>添加种子</b-dropdown-item-button>
            <b-dropdown-item-button @click="allswitch(false)">全部关闭</b-dropdown-item-button>
            <b-dropdown-item-button @click="allswitch(true)">全部启动</b-dropdown-item-button>
          </b-dropdown>
        </div>
      </div>
    </div>
    <div class="card-body pt-0">
      <div class="table-responsive">
        <b-table
          class="table-centered"
          :items="ordersData"
          :fields="fields"
          responsive="sm"
          :per-page="perPage"
          :current-page="1"
          thead-class="thead-light"
          @filtered="onFiltered"
        >
          <template v-slot:cell(seedswitch)="row">
            <div>
              <b-form-checkbox @change="changeswitch(row)" v-model="row.value" switch></b-form-checkbox>
            </div>
          </template>
          <template v-slot:cell(viewState)="row">
            <span @click="journal(row.item)" style="cursor: pointer;">日志</span>
            <span style="margin:0 3px;">|</span>
            <span @click="datahouse(row.item)" style="cursor: pointer;">数据</span>
          </template>
          <template v-slot:cell(configure)="row">
            <!-- <a :href="'/spider_detail/' + row.item.flowId" target="_blank">查看</a> -->
            <span @click="goSpiderDetailPage(row.item.flowId)" style="color:#5664d2;cursor: pointer;">查看</span>
          </template>
        </b-table>
      </div>
      <div class="row">
        <div class="col">
          <div class="dataTables_paginate paging_simple_numbers float-right">
            <ul class="pagination pagination-rounded mb-0">
              <!-- pagination -->
              <b-pagination v-model="currentPage" :total-rows="totalRows" :per-page="perPage"></b-pagination>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.showerror{
  display: block;
}
.butn{
  ::v-deep .btn{
    background-color: #252b3b;
    border-color: #252b3b;
    border-radius: 30px;
    display: flex;
    align-items: center;
  }
  ::v-deep .btn-secondary.focus {
    box-shadow: 0 0 0 0.15rem rgb(37 40 58 / 50%);
  }
}
.search-box{
  margin-top: 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.allNum{
  width: 100%;
  // padding-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.searchNum{
  span{
    font-size: 1rem;
    color: #3444c1;
    margin: 0 4px;
    font-weight: 600;
  }
}
</style>
